<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <link rel="stylesheet" type="text/css" href="./css/aui.css" />
    <link rel="stylesheet" type="text/css" href="./css/styleold.css" />
    <link rel="stylesheet" type="text/css" href="./css/style.css" />
    <link rel="stylesheet" type="text/css" href="./css/percircle.css" />
    <script type="text/javascript" src="./script/api.js"></script>
    <script type="text/javascript" src="./script/base.js"></script>
    <script type="text/javascript" src="./script/jquery.min.js"></script>
</head>
<body>
    <header class="aui-bar aui-bar-nav">
        <a class="aui-pull-left" tapmode onclick="closeWin()">
            <span class="aui-iconfont aui-icon-left"></span>
        </a>
        <div class="aui-title">修改密码</div>
    </header>
    <div class="aui-bar-nav-d"></div>

    <ul class="user-password">
        <li>
            <label>新密码</label>
            <input class="text-1" type="text" placeholder="请输入新的登录密码" id="user_pwd">
            <div class="check" id="checkPSW"></div>
        </li>
        <li>
            <label>确认新密码</label>
            <input class="text-1" type="text" placeholder="请再次输入新的登录密码" id="user_pwd_confirm">
            <div class="check" id="checkPSW_2"></div>
        </li>
    </ul>

    <div class="user-data-btn" tapmode onclick="fixPwd()">确认修改</div>

</body>
<script type="text/javascript">

// 确认修改
function fixPwd(){
        // 手机号
        // var mobile = $api.byId('mobile');
        // var mobileValue = $api.getStorage('mobile');
        var mobileValue = api.pageParam.mobileValue;
        // 验证码
        // var sms_code = $api.byId('sms_code');
        var sms_codeValue = api.pageParam.sms_codeValue;
        // 新密码
        var user_pwd = $api.byId('user_pwd');
        var user_pwdValue = user_pwd.value;
        // 确认新密码
        var user_pwd_confirm = $api.byId('user_pwd_confirm');
        var user_pwd_confirmValue = user_pwd_confirm.value;

        // // 手机号不能为空
        // if (!mobileValue) {
        //     $api.byId('checkPhone').innerText = '手机号不能为空';
        //     return false;
        // }else{
        //     $api.byId('checkPhone').innerText = '';
        // }
        // // 验证码不能为空
        // if (!sms_codeValue) {
        //     $api.byId('checkCaptcha').innerText = '验证码不能为空';
        //     return false;
        // }else{
        //     $api.byId('checkCaptcha').innerText = '';
        // }
        // // 验证验证码
        // if (sms_codeValue != lastCaptcha) {
        //     $api.byId('checkCaptcha').innerText = '验证码错误';
        //     return false;
        // }else{
        //     $api.byId('checkCaptcha').innerText = '';
        // }


        // 密码不能为空
        if (!user_pwdValue) {
            $api.byId('checkPSW').innerText = '密码不能为空';
            return false;
        }else{
            $api.byId('checkPSW').innerText = '';
        }
        // 再次输入密码不能为空
        if (!user_pwd_confirmValue) {
            $api.byId('checkPSW_2').innerText = '请再次输入密码';
            return false;
        }else{
            // 两次密码输入是否相同
            if (user_pwdValue != user_pwd_confirmValue) {
                $api.byId('checkPSW_2').innerText = '两次密码输入不一致';
                return false;
            }else{
                $api.byId('checkPSW_2').innerText = '';
            }
        }

        api.ajax({
         url: webAddress + '/index.php?ctl=app_user_center&act=reset_password',
         method: 'post',
         data: {
          values: { 
           mobile: mobileValue,
           sms_code: sms_codeValue,
           pwd_m: user_pwdValue,
       },
   }
},function(ret, err){
 if (ret) {
  if (ret.status == 0) {
   alert(ret.info);
   return false;
}else{
   alert('重置密码成功');
   $api.setStorage('mobile', mobileValue);
   var funName = 'setMobile();';
   api.execScript({
    name: 'login',
    script: funName,
});
             // api.closeWin();
             api.closeToWin({
               name: 'login'
           });
         }
     } else {
        alert(err.msg);
    }
});
    }


    function user(){
        var delay = 0;
        if(api.systemType != 'ios'){
            // delay = 300;
        }
        api.openWin({
            name: 'user',
            url: './user.html',
            bounces:false,
            delay: delay,
            slidBackEnabled:true,
            vScrollBarEnabled:false,
            progress:{
                type:"page"
            }
        });
    };
    function closeWin(){
        api.closeWin({
        });
    }

</script>
</html>